﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Microsoft.Practices.Unity;
using ASPItalia.ModelVirtualCasting;
using ASPItalia.ModelVirtualCasting.WPF.Common.Helpers;

namespace ASPItalia.ModelVirtualCasting.WPF.ViewModels
{
    public class ViewModelsContext
    {
        private static Lazy<ViewModelsContext> _context;

        static ViewModelsContext()
        {
            _context = new Lazy<ViewModelsContext>(() => Container.Resolve<ViewModelsContext>(), true);
        }

        public ViewModelsContext()
        {
            // Register default ViewModels. No configuration or abstraction for this layer
            Container.RegisterInstance(typeof(MainViewModel), new MainViewModel());
            Container.RegisterInstance(typeof(TaskbarViewModel), new TaskbarViewModel());
        }

        /// <summary>
        /// Get current unity container
        /// </summary>
        protected static IUnityContainer Container
        {
            get
            {
                return ApplicationContext.Current.Container;
            }
        }

        /// <summary>
        /// Singleton instance
        /// </summary>
        public static ViewModelsContext Current
        {
            get { return _context.Value; }
        }

        /// <summary>
        /// Get the main view model
        /// </summary>
        public MainViewModel MainViewModel
        {
            get { return Container.Resolve<MainViewModel>(); }
        }

        /// <summary>
        /// Get the view model used to receive remote tasks
        /// </summary>
        public TaskbarViewModel TaskbarViewModel
        {
            get { return Container.Resolve<TaskbarViewModel>(); }
        }
    }
}
